<?php

namespace App\Controllers\Opinion;

use App\Models\Opinion\Opinion;

class PushOpinion extends \App\Libs\Base\BaseAction
{
    protected function beforeRun()
    {
        parent::beforeRun();
        //$this->needLogin = TRUE;
    }

//提交意见：建议
    public function execute()
    {
        if($this->request->hasPost('content')){
            $content = trim($this->request->getPost('content'));
//            $uid = $this->request->getPost('uid');
            $uid = $this->session->user->id;
            $opinionModel = new Opinion();
            $res = $opinionModel->create(array(
                'uid'=> $uid,
                'content'=> $content,
                'ctime'=> date('Y:m:d H:i:s')
            ));
            if($res){
                return \App\Libs\Views\Json::view(0, '提交成功，感谢您的反馈!', null);
            }else{
                return \App\Libs\Views\Json::view(1, '失败，服务器异常，请重试!', null);
            }
        }else{
            return \App\Libs\Views\Json::view(1, '内容不能为空', null);
        }
    }
}
